python批量图片转pdf,将TIFF图像批量转换为PDF ImageMagick Python

您所在的位置:网站首页 tif 转 pdf python批量图片转pdf,将TIFF图像批量转换为PDF ImageMagick Python

python批量图片转pdf,将TIFF图像批量转换为PDF ImageMagick Python

2024-01-25 06:57| 来源: 网络整理| 查看: 265

这里是我创建的一个纯python实现,它不依赖ImageMagick。它只依赖于PIL和reportlab。它可以在谷歌应用程序引擎这样的受限环境下运行。def TIFF2PDF(tiff_str, max_pages = 200):

'''

Convert a TIFF Image into a PDF.

tiff_str: The binary representation of the TIFF.

max_pages: Break after a number of pages. Set to None to have no limit.

'''

import PIL

import reportlab

import reportlab.lib.pagesizes as pdf_sizes

from cStringIO import StringIO

logging.info("TIFF2PDF")

# Open the Image in PIL

tiff_img = PIL.Image.open(StringIO(tiff_str))

# Get tiff dimensions from exiff data. The values are swapped for some reason.

height, width = tiff_img.tag[0x101][0], tiff_img.tag[0x100][0]

# Create our output PDF

out_pdf_io = StringIO()

c = reportlab.pdfgen.canvas.Canvas(out_pdf_io, pagesize = pdf_sizes.letter)



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3